//package com.wulaobo.test;
//
//import com.wulaobo.pojo.Event;
//import org.apache.flink.connector.jdbc.JdbcConnectionOptions;
//import org.apache.flink.connector.jdbc.JdbcExecutionOptions;
//import org.apache.flink.connector.jdbc.JdbcSink;
//import org.apache.flink.streaming.api.datastream.DataStreamSource;
//import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
//
///**
// * @description:
// * @author： wuwenbo
// * @date： 2022-07-20 18:58
// */
//public class SinkToMySQL {
//
//    public static void main(String[] args) throws Exception {
//        StreamExecutionEnvironment env =
//                StreamExecutionEnvironment.getExecutionEnvironment();
//        env.setParallelism(1);
//
//        DataStreamSource<Event> stream = env.fromElements(
//                new Event("Mary", "./home", 1000L),
//                new Event("Bob", "./cart", 2000L),
//                new Event("Alice", "./prod?id=100", 3000L),
//                new Event("Alice", "./prod?id=200", 3500L),
//                new Event("Bob", "./prod?id=2", 2500L),
//                new Event("Alice", "./prod?id=300", 3600L),
//                new Event("Bob", "./home", 3000L),
//
//                new Event("Bob", "./prod?id=1", 2300L),
//                new Event("Bob", "./prod?id=3", 3300L));
//        stream.addSink(
//                JdbcSink.sink(
//                        "INSERT INTO clicks (user, url) VALUES (?, ?)",
//                        (statement, r) -> {
//                            statement.setString(1, r.user);
//                            statement.setString(2, r.url);
//                        },
//                        JdbcExecutionOptions.builder()
//                                .withBatchSize(1000)
//                                .withBatchIntervalMs(200)
//                                .withMaxRetries(5)
//                                .build(),
//                        new
//                                JdbcConnectionOptions.JdbcConnectionOptionsBuilder()
//                                .withUrl("jdbc:mysql://192.168.0.151:3306/test1")
//                                                // 对于 MySQL 5.7，用"com.mysql.jdbc.Driver"
//                                                .withDriverName("com.mysql.jdbc.Driver")
//                                                .withUsername("ziyun")
//                                                .withPassword("123456")
//                                                .build()
//                                )
//                );
//        env.execute();
//    }
//}
